﻿using System;
using System.Collections.Generic;

using System.Text;
using System.ComponentModel;

namespace TA.Turbo.Controls
{
	/// <summary>
	/// Base class for columns that output command controls (eg., buttons).
	/// </summary>
	public abstract class BaseCommandColumn : BasePresetColumn
	{
		#region PUBLIC
		#region INIT
		/// <summary>
		/// Ctor.
		/// </summary>
		public BaseCommandColumn()
		{
			this.Command = "";
		}
		#endregion
		#region EVENTS
		/// <summary>
		/// Raised when a command control is clicked.
		/// </summary>
		[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
		public SimpleClientEvent Click { get { return _click; } }
		#endregion
		#region PROPS
		/// <summary>
		/// The command name.
		/// </summary>
		[DefaultValue("")]
		public string Command { get; set; }
		/// <summary>
		/// Gets the client script to be executed when this column is clicked.
		/// </summary>
		/// <remarks>
		/// This property first checks <see cref="Click"/> event and if it has client-side handler, returns that.
		/// If not, it then checks the <see cref="Command"/> property and if it's not empty, builds and returns client-side handler which raises that command.
		/// If not, it returns null.
		/// </remarks>
		[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
		[Browsable(false)]
		public virtual string ClickClientJS
		{
			get
			{
				if (!string.IsNullOrEmpty(this.Click.Client))
					return this.Click.Client;
				if (!string.IsNullOrEmpty(this.Command))
					return string.Format("this.get_Container().FireCommand('{0}');", this.Command);
				return null;
			}
		}
		#endregion
		#endregion
		#region INTERNAL
		#region VARS
		SimpleClientEvent _click = new SimpleClientEvent();
		#endregion
		#region PROPS
		#endregion
		#endregion
	}
}
